<template>
  <ul class="switches">
    <li class="switch-item" :class="{'active': index === currentIndex}" v-for="(item, index) in switches" :key="index" @click="switchItem(index)">
      <span>{{item.name}}</span>
    </li>
  </ul>
</template>
<script>
export default {
  props: {
    switches: {
      type: Array,
      default: () => {}
    },
    currentIndex: {
      type: Number,
      default: 0
    }
  },
  methods: {
    // 当点击的时候派发给父组件一个事件
    switchItem(index) {
      this.$emit('switch', index)
    }
  }
}
</script>
<style lang="stylus" scoped>
@import "~common/stylus/variable"
.switches
  display: flex
  align-items: center
  width: 240px
  margin: 0 auto
  border: 1px solid #333
  border-radius: 5px
  .switch-item
    flex: 1
    padding: 8px
    text-align: center
    font-size: 14px
    color: hsla(0, 0%, 100%, 0.3)
    &.active
      background: $color-highlight-background
      color: $color-text
</style>
